{smcl}
{* *! version 1.0.3  27jan2015  Ben Jann}{...}
{cmd:help addplot}{right: ({browse "http://www.stata-journal.com/article.html?article=gr0065":SJ15-3: gr0065})}
{hline}

{title:Title}

{p2colset 5 16 18 2}{...}
{p2col :{hi:addplot} {hline 2}}Adding twoway plot objects to an existing twoway graph{p_end}
{p2colreset}{...}


{title:Syntax}

{p 8 11 2}
{cmd:addplot} [{it:graphname}] [{it:{help numlist}}] {cmd::} {it:{help twoway:twoway_plots}}

{phang}
{it:graphname} is the name of the memory graph to be modified.  The current
(topmost) graph is used if {it:graphname} is omitted.

{phang}
{it:numlist} provides the numbers of the subgraphs to be modified
(shorthand conventions as explained in help {it:{help numlist}} apply).
This is useful if you apply {cmd:addplot} to a graph that has been
created using {helpb graph combine} or the {help by_option:{bf:by()}}
option.  The default is to modify all twoway subgraphs found in the
graph.  If you only want to modify, say, the second and third subgraph,
you could type

        {cmd:. addplot 2 3:} ...

{phang}
The {cmd:norescaling} option: When you modify a plot using {cmd:addplot}, the
axes of the plot will be recompiled using default settings.  This is to ensure
that all data points fit into the plot region, even if they are outside the
range of the existing plot.  To prevent {cmd:addplot} from recompiling the
axes (so that axis labels and ranges are preserved), apply option
{cmd:norescaling} to the added twoway command.  See the example on
{help addplot##norescaling:Addressing subgraphs in a by-graph} below.

{phang}
The legend: {cmd:addplot} may cause a legend to be added to the
graph.  To suppress adding a legend, apply option {cmd:legend(off)} to
the added twoway command (see the first example below).  Furthermore,
{cmd:addplot} always re-creates an existing legend using default legend
keys.  To preserve or create a custom legend, you must specify an
appropriate {cmd:legend(order())} option with the added twoway command
(see {manhelpi legend_options G-3}).


{title:Description}

{pstd}
{cmd:addplot} adds twoway plot objects to an existing twoway
graph.  This is useful if you want to add objects such as titles or
extra data points to a twoway graph after it has been created.  Most of
what {cmd:addplot} can do can also be done by rerunning the original
graph command and including additional options or plot statements.
{cmd:addplot}, however, might be useful if you have to modify a graph
for which you cannot rerun the original command, for example, because
you have only the graph file but not the data that were used to create
the graph.  Furthermore, {cmd:addplot} can do certain things that would
be difficult to achieve in one graph command (for example, customizing
individual subgraphs within a by-graph).  {cmd:addplot} also provides a
substitute for some of the functionality of the
{help Graph Editor}.


{title:Examples}

{pstd}
Basic example:{p_end}
{phang2}. {bf:{stata sysuse auto}}{p_end}
{phang2}. {bf:{stata scatter price mpg}}{p_end}
{phang2}. {bf:{stata "addplot: scatter price mpg if price>15000, ms(i) mlabel(make) legend(off)"}}{p_end}
{phang2}. {bf:{stata `"addplot: pcarrowi 14000 23 15500 21.5 "expensive car""'}}{p_end}
{phang2}. {bf:{stata "addplot: (line price mpg if mpg>30) (dropline price mpg if price<3300)"}}{p_end}
{phang2}. {bf:{stata graph drop Graph}}{p_end}

{pstd}
Working with named graphs:{p_end}
{phang2}. {bf:{stata sysuse auto}}{p_end}
{phang2}. {bf:{stata scatter price mpg, name(g1, replace)}}{p_end}
{phang2}. {bf:{stata scatter price weight, name(g2, replace)}}{p_end}
{phang2}. {bf:{stata "addplot g1: , title(price by mpg)"}}{p_end}
{phang2}. {bf:{stata "addplot g2: , title(price by weight)"}}{p_end}
{phang2}. {bf:{stata graph drop g1 g2}}{p_end}
        
{pstd}
Modifying a graph from file:{p_end}
{phang2}. {bf:{stata sysuse auto}}{p_end}
{phang2}. {bf:{stata scatter price mpg}}{p_end}
{phang2}. {bf:{stata graph save mygraph.gph}}{p_end}
{phang2}. {bf:{stata graph drop Graph}}{p_end}
{phang2}. ...{p_end}
{phang2}. {bf:{stata graph use mygraph.gph}}{p_end}
{phang2}. {bf:{stata `"addplot mygraph: pcarrowi 14000 23 15500 21.5 "expensive car", legend(off)"'}}{p_end}
{phang2}. {bf:{stata graph drop mygraph}}{p_end}
{phang2}. {bf:{stata erase mygraph.gph}}{p_end}

{marker norescaling}{...}
{pstd}
Addressing subgraphs in a by-graph:{p_end}
{phang2}. {bf:{stata sysuse auto}}{p_end}
{phang2}. {bf:{stata scatter price mpg, by(foreign)}}{p_end}
{phang2}. {bf:{stata "addplot: , xline(21.3, lp(dash)) yline(6165, lp(dash)) norescaling"}}{p_end}
{phang2}. {bf:{stata "addplot 1: , xline(19.8) yline(6072) norescaling"}}{p_end}
{phang2}. {bf:{stata "addplot 2: , xline(24.8) yline(6385) norescaling"}}{p_end}
{phang2}. {bf:{stata graph drop Graph}}{p_end}


{title:Acknowledgment}

{pstd}
Vince Wiggins from StataCorp provided critical help and comments.{p_end}


{title:Author}

{pstd}Ben Jann{p_end}
{pstd}University of Bern{p_end}
{pstd}Bern, Switzerland{p_end}
{pstd}ben.jann@soz.unibe.ch{p_end}
    

{title:Also see}

{p 4 14 2}Article:  {it:Stata Journal}, volume 15, number 3: {browse "http://www.stata-journal.com/article.html?article=gr0065":gr0065}

{p 7 14 2}Help: {manhelp graph_twoway G-2:graph twoway}, {manhelp graph_combine G-2:graph combine}, {manhelp by_option G-3:{it:by_option}},
{manhelp addplot_option G-3:{it:addplot_option}}, {manhelp graph_editor G-1:graph editor}{p_end}
